Skip to content

libstore: Make HTTP binary cache uploads run in constant memory#14390

Merged
Ericson2314 merged 3 commits intomasterfrom
constant-memory-uploads
Oct 29, 2025
Merged

libstore: Make HTTP binary cache uploads run in constant memory#14390
Ericson2314 merged 3 commits intomasterfrom
constant-memory-uploads

Conversation

@xokdvium
Copy link
Contributor

Motivation

This makes uploads to HTTP binary caches (including the newly reworked S3 store) run in constant memory. Instead of buffering everything in a string we now do uploads from a single-pass (and optionally restartable for seeking) source.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@xokdvium xokdvium requested review from Mic92 and tomberek October 28, 2025 00:01
@github-actions github-actions bot added store Issues and pull requests concerning the Nix store fetching Networking with the outside (non-Nix) world, input locking labels Oct 28, 2025
@xokdvium xokdvium force-pushed the constant-memory-uploads branch 4 times, most recently from 312b2c3 to f569a03 Compare October 28, 2025 00:41
Copy link
Member

@lovesegfault lovesegfault left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

if (compressionMethod) {
data = compress(*compressionMethod, data);
StringSink sink{};
auto compressionSink = makeCompressionSink(*compressionMethod, sink);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So future work is makeCompressionSource? :) Or should we use sinkToSource?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sinkToSource don't think we can. Can't use coroutines easily in curl callbacks. I have a feeling that this will be fine for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I just wanted to avoid copying stuff twice in memory (like logs) and stuffing it straight into a compression sink. That should be slightly more optimal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the boost coroutine stuff here smells like bad luck. Fine to keep this case memory buffered for now.

@Ericson2314 Ericson2314 added this pull request to the merge queue Oct 29, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 29, 2025
@Ericson2314 Ericson2314 added this pull request to the merge queue Oct 29, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 29, 2025
Make uploads run in constant memory. Also change the callbacks to be
noexcept, since we really don't want to be unwinding the stack in the
curl thread. That will definitely corrupt that stack and make nix/curl
crash in very bad ways.
@Ericson2314 Ericson2314 force-pushed the constant-memory-uploads branch from c6c5d96 to cf75079 Compare October 29, 2025 22:35
@Ericson2314 Ericson2314 enabled auto-merge October 29, 2025 22:58
@Ericson2314 Ericson2314 added this pull request to the merge queue Oct 29, 2025
Merged via the queue into master with commit bffbdcf Oct 29, 2025
21 checks passed
@Ericson2314 Ericson2314 deleted the constant-memory-uploads branch October 29, 2025 23:58
@edolstra edolstra mentioned this pull request Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fetching Networking with the outside (non-Nix) world, input locking store Issues and pull requests concerning the Nix store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants